-
-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DB/DirectDatabaseQuery: implement PHPCSUtils and support modern PHP #2186
DB/DirectDatabaseQuery: implement PHPCSUtils and support modern PHP #2186
Conversation
This code is a remnant of the old-style custom ignore comment mechanism which was removed in 2063.
... to cover the one uncovered line.
👉 This change will be easier to review while ignoring whitespace changes.
…ator Prevent false negatives in case someone would use the PHP 8.0 nullsafe object operator on the `$wpdb` variable. Also makes the token walking more stable by preventing an unrelated object operator from being recognized as if it were an operator operating on the `$wpdb` object (false positive). Includes tests.
Don't allow the sniff to get confused by comments. Related to 763 Includes tests.
Prevent false positives from walking too far when a database query statement is ended by a PHP close tag. Includes unit tests.
Prevent unsolvable false positives for `TRUNCATE` queries. Those cannot be cached and need a direct DB query. (second opinion appreciated!) Includes unit tests. Fixes 1947
Note: this sniff is not that stable as the token walking is not very strict. Realistically, it could do with a complete rewrite, but that is outside the scope of what I was trying to achieve now. Also just saw #864, which makes me question the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with TRUNCATE
not being flagged.
In most cases people using raw SQL know why they are doing it and if they know how to configure PHPCS they'll just exclude the error for where it's being used anyhow so 🤷🏼♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
DB/DirectDatabaseQuery: remove redundant code
This code is a remnant of the old-style custom ignore comment mechanism which was removed in #2063.
DB/DirectDatabaseQuery: add missing test case
... to cover the one uncovered line.
DB/DirectDatabaseQuery: implement PHPCSUtils
👉 This change will be easier to review while ignoring whitespace changes.
DB/DirectDatabaseQuery: add support for PHP 8.0+ nullsafe object operator
Prevent false negatives in case someone would use the PHP 8.0 nullsafe object operator on the
$wpdb
variable.Also makes the token walking more stable by preventing an unrelated object operator from being recognized as if it were an operator operating on the
$wpdb
object (false positive).Includes tests.
DB/DirectDatabaseQuery: bug fix - code style independent token walking
Don't allow the sniff to get confused by comments.
Related to #763
Includes tests.
DB/DirectDatabaseQuery: bug fix - finding end of statement
Prevent false positives from walking too far when a database query statement is ended by a PHP close tag.
Includes unit tests.
DB/DirectDatabaseQuery: bug fix - ignore TRUNCATE queries
Prevent unsolvable false positives for
TRUNCATE
queries. Those cannot be cached and need a direct DB query. (second opinion appreciated!)Includes unit tests.
Fixes #1947